﻿/*09. Write a program that finds the most frequent number in an array. Example:
	{4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3}  4 (5 times) */

using System;

class MostFrequentNumberInArray
{
    static void Main()
    {
        int[] arr = { 1, 2, 3, 4, 5, 62, 0 };

        int counter = 1;
        int maxCounter = 0;
        int mostFrequent = 0;

        for (int i = 0; i < arr.Length - 1; i++)
        {
            for (int j = i; j < arr.Length - 1; j++)
            {

                if (arr[i] == arr[j + 1])
                {
                    counter++;
                }
                if (maxCounter < counter)
                {
                    maxCounter = counter;
                    mostFrequent = arr[i];
                }
            }
            counter = 0;
        }
        if (maxCounter > 1)
        {
            Console.WriteLine("The number is [{0}] ", mostFrequent);
            Console.WriteLine("It repeats [{0}] times", maxCounter);
        }
        else
        {
            Console.WriteLine("All numbers are different");
        }
    }
}

